package fy.hr.reinstatement;

import org.springframework.web.servlet.ModelAndView;

import fy.form.listen.dao.MyOrgManager;
import fy.util.MyJSONConvert;

import java.util.List;


public final class ReinstatementManager {

	public static final String QUERY_MEMBER_INFO_OPERATE = "1";
	public static final String CORP_SELECT_OPERATE = "2";
	public static final String DEP_SELECT_OPERATE = "3";
	public static final String CHILD_DEP_SELECT_OPERATE = "4";

	/**
	 * 获取人员信息
	 * 
	 * @return
	 */
	public static void queryInfo(ModelAndView modelAndView, long loginMemberID,
			String memberCode) {

		com.seeyon.ctp.organization.bo.V3xOrgMember member = MyOrgManager.getInstance().getMemberByID(
				loginMemberID);
		if (memberCode == null || "".equals(memberCode)) {
			modelAndView.addObject("jsonStr",
					"{success:false,error:'复职人员编号不能为空，确认工号重新查询。'}");
		} else if (member == null) {
			modelAndView.addObject("jsonStr",
					"{success:false,error:'未查到到对应的填单人，请重试，或者联系OA系统管理员。'}");
		} else {
			String loginMemberCode = member.getCode();
			if (loginMemberCode == null || "".equals(loginMemberCode)) {
				modelAndView.addObject("jsonStr",
						"{success:false,error:'OA用户的人员编码不能为空，请联系制造部OA管理员。'}");
			} else {
				ReinstatementDao dao = new ReinstatementDao();
				dao.setMemberCode(memberCode);
				dao.setLoginMemberCode(loginMemberCode);

				if (dao.query()) {
					try {
						modelAndView.addObject(
								"jsonStr",
								"{success:true,data:"
										+ MyJSONConvert.toJSONStr(dao
												.getReinstatementInfoBean())
										+ "}");

					} catch (Exception e) {
						e.printStackTrace();
					}
				} else {
					modelAndView.addObject("jsonStr", "{success:false,error:'"
							+ dao.getErrorMsg() + "'}");
				}
			}
		}
	}

	public static void queryDepAndPost(ModelAndView modelAndView, String pk,
			String operate) {
		
		if (pk != null && !"".equals(pk)) {

			DepAndPostDao dao = new DepAndPostDao();

			boolean success = false;
			if (CORP_SELECT_OPERATE.equals(operate)) {
				success = dao.queryDepByCorp(pk);
			} else if (DEP_SELECT_OPERATE.equals(operate)) {
				success = dao.queryPostAndChildDepByDep(pk);
			} else if (CHILD_DEP_SELECT_OPERATE.equals(operate)) {
				success = dao.queryPostsByDep(pk);
			} else {
				modelAndView.addObject("jsonStr", "{success:false,error:'不合法操作'}");
				return;
			}

			if (success) {
				try {
					modelAndView.addObject("jsonStr", "{success:true,data:"
							+ MyJSONConvert.toJSONStr(dao.getDepBean()) + "}");

				} catch (Exception e) {
					e.printStackTrace();
				}
			} else {
				modelAndView.addObject("jsonStr", "{success:false,error:'"
						+ dao.getErrorMsg() + "'}");
			}
		} else {
			modelAndView.addObject("jsonStr", "{success:false,error:'参数不能为空'}");
		}
	}
}
